/**
 * Created by wupan on 2016/10/21.
 */
package com.buss.service.base;

import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public abstract class BaseService<T> implements IBaseService<T> {

    @Autowired
    protected Mapper<T> mapper;
    public Mapper<T> getMapper() {
        return mapper; /** 获取Mapper */
    }

    public List<T> select(T record){
        return mapper.select(record);
    }
    public List<T> selectByExample(Object example) {
        return mapper.selectByExample(example);
    }
    public List<T> selectByExample2Page(Object example, int page, int rows){
        PageHelper.startPage(page, rows);  //分页查询
        return selectByExample(example);
    }
    public T selectOne(T record){
        return mapper.selectOne(record);
    }

    public int selectCount(T record) {
        return mapper.selectCount(record);
    }

    public int selectCountByExample(Object example) {
        return mapper.selectCountByExample(example);
    }

    public T selectByPrimaryKey(Object key) {
        return mapper.selectByPrimaryKey(key);
    }

    public int insert(T entity) {
        return mapper.insert(entity);
    }

    public int updateByPrimaryKey(T entity) {
        return mapper.updateByPrimaryKey(entity);
    }

    public int deleteByPrimaryKey(Object key) {
        return mapper.deleteByPrimaryKey(key);
    }

    public int deleteByExample(Object example) {
        return mapper.deleteByExample(example);
    }

    public int updateByPrimaryKeySelective(T entity) {
        return mapper.updateByPrimaryKeySelective(entity);
    }

    //TODO 其他...
}
